<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('路线管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">线路名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="xlmc" name="xlmc" placeholder="线路名称"/>
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
                <div class="group-button tpl-button" id="toolbar">
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="routeTable"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script th:inline="javascript">
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton','formSelects'], function () {

        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            formSelects=layui.formSelects,
            tablebtn = layui.tablebutton;
        var $table;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function () {
                    zzpUtils.refreshTable("#routeTable");
                },
                //新增
                addEvent: function (data) {
                    add();
                },
                //修改
                editEvent: function (data) {
                    if (data.row != undefined) {
                        editDialog(data.row.id);
                    }
                },
                //删除
                deleteEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id);
                        delDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            delDialog(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                }
            }
        });
        //新增路线
        function add() {
            zzpUtils.dialog({
                title: "新增路线",
                type: 2,
                content: "/base/addLx",
                area: ['80%', '80%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#routeTable");
                }
            });
        }
        //编辑
        function editDialog(id){
            zzpUtils.dialog({
                title: "修改路线",
                type: 2,
                content: "/base/updateLx?id="+id,
                area: ['80%', '80%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#routeTable");
                }
            });
        }

        //删除
        function delDialog(ids) {
            zzpUtils.confirm("您将删除路线", function (index) {
                zzpUtils.action({
                    url: "/wmsline/zuoFie",
                    data: JSON.stringify({ids: ids}),
                    success: function (data) {
                        setTimeout(function () {
                            if (data.type == 'success') {
                                layer.msg(data.title);
                            } else {
                                layer.msg(data.message);
                            }
                        }, 500);
                        zzpUtils.refreshTable("#routeTable");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }


        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff'
        })
        $table = zzpUtils.table({
            elem: '#routeTable',
            isApi: true,
            isOperate: true,
           // functions: functions.tableBtn,
            url: '/wmsline/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'xlmc',
                title: '线路名称'
            }, {
                field: 'jhkw',
                title: '集货库位'
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter
        });
        function operateFormatter(value, row, index) {
            var  button = '', buttons1 = '', buttons2 = '';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                /*var item = functions.tableBtn[i];
                var btn = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';*/
                var btn = '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name + '</button>';

                buttons1 += btn;
            }

            return buttons1;
        }

    });
</script>
</html>